<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>chatgpt文字输出效果</h1>
    <p id="content"></p>
    <script>
        // 建立连接
        const source = new EventSource('http://localhost:3000/article');
        let str = '';
        // 接收信息
        source.onmessage = function (e) {
            if (e.data === 'end') {
                // 判断end，关闭连接
                source.close()
            }

            str += e.data
            // 实时输出字符串
            console.log(str)
            document.getElementById("content").innerHTML = str;
        };
    </script>
</body>

</html>